package com.starpl.mobile.android.monthunsae.november.activity;

import java.util.Calendar;

import android.os.Bundle;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.starpl.mobile.android.monthunsae.november.R;
import com.starpl.mobile.android.monthunsae.november.domain.MonthUnsae;
import com.starpl.mobile.android.monthunsae.november.handler.CalendarGridHandler;
import com.starpl.mobile.android.platform.common.DateUtil;
import com.starpl.mobile.android.platform.common.base.BaseActivity;
import com.starpl.mobile.android.platform.common.base.BaseApplication;
import com.starpl.mobile.android.platform.component.StarplGridView;


/**
 * 연애운 및 재물운 캘린더 액티비티
 * 
 * @author 우연화
 * @since 2011.03.17
 */
public class UnsaeCalendarActivity extends BaseActivity
{
	private final int LOVE_UNSAE = 10084402;
	private final int MONEY_UNSAE = 10001374;

	private TextView mTvTitle;
	private TextView mTvYearMonth;
	private ImageView mIvGoodBad;
	
	private LinearLayout mLlCalendar;
	private CalendarGridHandler mGirdHanlder;
	
	private ImageView mIvUnsaeIconLove;
	private ImageView mIvUnsaeIconMoney;
	private TextView mTvUnsaeName;
	private TextView mTvContent;

	private int mKeywordIdx;

	private MonthUnsae mMonthUnsae;
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.starpl.platform.common.base.BaseActivity#onCreate(android.os.Bundle)
	 */
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.unsae_calendar_activity);

		mTvTitle = (TextView) findViewById(R.id.unsae_calendar_activity_tv_title);
		mTvYearMonth = (TextView) findViewById(R.id.unsae_calendar_activity_tv_year_month);
		mIvGoodBad = (ImageView)findViewById(R.id.unsae_calendar_activity_iv_goodbad);
		
		mLlCalendar = (LinearLayout)findViewById(R.id.unsae_calendar_activity_ll_calendar);
		
		mIvUnsaeIconLove = (ImageView)findViewById(R.id.unsae_calendar_activity_iv_icon_love);
		mIvUnsaeIconMoney = (ImageView)findViewById(R.id.unsae_calendar_activity_iv_icon_wealth);
		mTvUnsaeName = (TextView)findViewById(R.id.unsae_calendar_activity_tv_unsae_name);
		mTvContent = (TextView) findViewById(R.id.unsae_calendar_activity_tv_unsae_info);

		mKeywordIdx = getIntent().getExtras().getInt("keywordIdx", 0);
		
		mMonthUnsae = (MonthUnsae) BaseApplication.getGlobalPersistent("monthUnsae");
	}

	/* (non-Javadoc)
	 * @see com.starpl.platform.common.base.BaseActivity#onResume()
	 */
	@Override
	protected void onResume()
	{
		super.onResume();

		Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.YEAR, Integer.parseInt(mMonthUnsae.getUnsaeDate().substring(0, 4)));
		calendar.set(Calendar.MONTH, Integer.parseInt(mMonthUnsae.getUnsaeDate().substring(5, 7))-1);
		calendar.set(Calendar.DAY_OF_MONTH, 1);
		
		mGirdHanlder = new CalendarGridHandler(this, mKeywordIdx, calendar);
		StarplGridView gridView = new StarplGridView(mGirdHanlder);
		mLlCalendar.removeAllViews();
		mLlCalendar.addView(gridView);
		
		DateUtil dateUtil = new DateUtil(mMonthUnsae.getUnsaeDate());
		
		mTvYearMonth.setText(dateUtil.toStringByFormat("yyyy년 M월"));
		
		if(mKeywordIdx == LOVE_UNSAE)
		{
			mTvTitle.setText("연애운 캘린더");
			mTvUnsaeName.setText("이달의 연애운");
			mTvContent.setText(mMonthUnsae.getLoveContent());
			
			mIvGoodBad.setBackgroundResource(R.drawable.img_calendar_love);
			
			mIvUnsaeIconLove.setVisibility(ImageView.VISIBLE);
			mIvUnsaeIconMoney.setVisibility(ImageView.INVISIBLE);
		}
		else if(mKeywordIdx == MONEY_UNSAE)
		{
			mTvTitle.setText("재물운  캘린더");
			mTvUnsaeName.setText("이달의 재물운");
			mTvContent.setText(mMonthUnsae.getMoneyContent());
			
			mIvGoodBad.setBackgroundResource(R.drawable.img_calendar_money);
			
			mIvUnsaeIconLove.setVisibility(ImageView.INVISIBLE);
			mIvUnsaeIconMoney.setVisibility(ImageView.VISIBLE);
		}
		
	}

}
